﻿using Microsoft.Win32;
using System; using Extra.ERP;

namespace AttLogs
{
    internal class SearchforUSBCom
    {
        public bool SearchforCom(ref string sCom)
        {
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM");
            string[] valueNames = key.GetValueNames();
            for (int i = 0; i < valueNames.Length; i++)
            {
                string str = "";
                str = key.GetValue(valueNames[i]).ToString();
                if (str != "")
                {
                    sCom = "";
                    if (valueNames[i] == @"\Device\USBSER000")
                    {
                        for (int j = 0; j <= 10; j++)
                        {
                            string str2 = "";
                            RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB\VID_1B55&PID_B400\" + j.ToString() + @"\Device Parameters");
                            if (key2 != null)
                            {
                                str2 = key2.GetValue("PortName").ToString();
                                if (str == str2)
                                {
                                    sCom = str2;
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }
}

